package ModelLayer;
import java.util.ArrayList;



public class AddressBook
{
    private ArrayList<Person> persons;


    /**
     * Constructor for objects of class AdressBook
     */
    public AddressBook()
    {
       persons = new ArrayList<Person>();
    }
    
    /**
     * Add person to Person
     */
    public void addPerson(Person person)
    {
      this.persons.add(person);
    }
    
    /**
     * Find a person by his id
     */
    public Person getPerson(int id)
    {

        for (Person p : persons) {
            if(p == null){
                return null;
            }
                if (p.getId() == id){
                    return p;
                }   
        }
        return null;
    }
    
    /**
     * delete a person by his id
     */
    public void deletePerson(int id)
    {
      Person p = getPerson(id);
      persons.remove(p);

    }
    
    /**
     * Update a person by his id
     */
    public void updatePerson(int id, String name, String address, String postalCode, String city, String phone)
    {
        Person p = getPerson(id);
        p.updatePerson(name, address, postalCode, city, phone);
        //person.updatePerson(, name, address, postalCode, city, telephone);
        
      
    }
    public ArrayList<Person> listAllPersons()
    {
        int id = 0;
        Person person = getPerson(id);
        if(persons != null){
            if(persons.get(id) != null){
            return persons;
        }
        }
        return null;
    }
}


